package com.aispeech.testcustom.view;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.aispeech.testcustom.MainActivity;
import com.aispeech.testcustom.R;
import com.aispeech.testcustom.utils.PreferenceUtil;
import com.aispeech.testcustom.utils.TiLog;
import com.zys.brokenview.BrokenCallback;
import com.zys.brokenview.BrokenTouchListener;
import com.zys.brokenview.BrokenView;

public class SplashActivity extends AppCompatActivity {

    private BrokenView brokenView;
    private BrokenTouchListener bkListener;
    private TextView mTv;

    private Handler handler = new Handler();
    private Paint p;

    Runnable runnable=new Runnable(){
        @Override
        public void run() {
            startActivity(new Intent(SplashActivity.this, MainActivity.class));
            SplashActivity.this.finish();

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        if(!PreferenceUtil.SettingPreference.isShowSPlash(this)){
            startActivity(new Intent(SplashActivity.this, MainActivity.class));
            SplashActivity.this.finish();
        }

        mTv = (TextView) findViewById(R.id.fullscreen_content);
        brokenView = BrokenView.add2Window(this);

        p = new Paint();
        p.setColor(0xffffffff);
        bkListener = new BrokenTouchListener.Builder(brokenView).
                setComplexity(20).
                setPaint(p).
                build();
        mTv.setOnTouchListener(bkListener);
        brokenView.setCallback(new BrokenCallback() {
            @Override
            public void onFalling(View v) {
                TiLog.d("onFalling postDelayed 1s start MainActivity!");
                handler.postDelayed(runnable,800);
            }
        });

        //TODO design the guide for user

        //TODO do something check update or read custom cmd?
        //是否要将用户自定义的指令读取到内存?
    }

}
